package com.ioPackage;

/**
 * @ClassName RecursionDemo3
 * @Description 啤酒问题
 * @Author 2214361854
 * @Date 2022/2/27 17:48
 * @Version 1.0
 */
public class RecursionDemo3 {

    /**
     * totalNumber 可以喝酒的总数
     * lastCoverNumber 剩余盖子数
     * lastBottleNumber 剩余瓶子数
     */
    public static int totalNumber;
    public static int lastCoverNumber;
    public static int lastBottleNumber;

    public static void main(String[] args) {
        /**
         * 啤酒2元1瓶，4个盖子可以换瓶，两个空瓶可以换1瓶
         * 10可以喝多少酒，剩余多少空瓶喝盖子
         */
        int i = 10;
        buy(i);
        System.out.println(i+"钱，可以买"+totalNumber+"瓶酒");
        System.out.println("剩余盖子："+lastCoverNumber+"，瓶子："+lastBottleNumber);
    }

    public static void buy(int money) {
        //钱买酒数
        int buyNumber = money / 2;
        totalNumber += buyNumber;
        //盖子数
        int coverNumber = lastCoverNumber + buyNumber;
        //瓶子数
        int boottleNumber = lastBottleNumber + buyNumber;

        //将瓶子和盖子换算成钱
        int allMoney = 0;
        if (coverNumber >= 4) {
            allMoney += (coverNumber/4) * 2;
        }
        lastCoverNumber = coverNumber % 4;

        if (boottleNumber >= 2) {
            allMoney += (boottleNumber/2) * 2;
        }
        lastBottleNumber = boottleNumber % 2;

        if (allMoney >= 2) {
            buy(allMoney);
        }
    }
}
